package com.example.android.apis.view;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class BuildingsOverlay  extends Overlay{
	private GeoPoint pointToDraw;
	private int resourceId;

	public void setPointToDraw(GeoPoint point) {
		pointToDraw = point;
	}

	public GeoPoint getPointToDraw() {
		return pointToDraw;
	}
	
	public void setResourceIdToDraw(int id){
		resourceId = id;
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
			long when) {
		super.draw(canvas, mapView, shadow);

		// convert point to pixels
		Point screenPts = new Point();
		mapView.getProjection().toPixels(pointToDraw, screenPts);

		// add marker
		Bitmap bmp = BitmapFactory.decodeResource(mapView.getContext().getResources(),
				resourceId);
		
		canvas.drawBitmap(bmp, screenPts.x - bmp.getWidth()/2, screenPts.y - bmp.getHeight()/2, null);
		return true;
	}
}
